var e = require("../../@babel/runtime/helpers/toConsumableArray"),
  t = require("../../utils/http.js"),
  a = require("../../utils/api.js"),
  i = require("../../utils/weapp-qrcode.js"),
  r = require("../../utils/language/switchLanguage.js"),
  n = !1;
Page({
  data: {
    languageType: "",
    current: 0,
    is_show: !1,
    isShowQr: !1,
    content: {},
    electronicTickets: [],
    code_i: 0,
    code_j: 0,
    currentQR: 0,
    isShowQrcode: 0,
    qrcodeMaxAge: 16,
    qrcodeMinAge: 0,
    newOrderDetailInfoVOList: [],
    newOrderGropList: [],
  },
  onLoad: function (e) {
    this.initLanguage(),
      this.setData({ orderNo: e.orderNo }),
      this.getOrderDetail({ orderSn: e.orderNo }),
      this.getUniversalTicketConfig();
  },
  initLanguage: function () {
    var e = r.languageVersion(wx.getStorageSync("language"));
    this.setData({ _t: e, languageType: wx.getStorageSync("language") }),
      wx.setNavigationBarTitle({ title: e["订单信息"] });
  },
  hideID: function (e) {
    if ("string" == typeof e && e.length >= 15) {
      var t = e.length - 8,
        a = "*".repeat(t);
      return e.substr(0, 4) + a + e.substr(-4);
    }
    return "**********";
  },
  getUniversalTicketConfig: function () {
    var e = this;
    t.getUniversalTicketConfig().then(function (t) {
      e.setData({
        isShowQrcode: t.data.isShowQrcode,
        qrcodeMaxAge: t.data.qrcodeMaxAge,
        qrcodeMinAge: t.data.qrcodeMinAge,
      });
    });
  },
  getOrderDetail: function (a) {
    var i = this,
      r = this;
    t.getOrderDetail(a).then(function (t) {
      var a = i,
        n = t.data;
      r.setData({ content: n });
      var o = [],
        s = [],
        c = [];
      n.orderDetailInfoVOList &&
        n.orderDetailInfoVOList.map(function (t) {
          t.museumOrderUserVOS &&
            2 == t.ticketClassify &&
            c.push({ parenting: t.museumOrderUserVOS }),
            t.museumOrderUserVOS &&
              2 !== t.ticketClassify &&
              s.push.apply(s, e(t.museumOrderUserVOS));
        }),
        s.forEach(function (e) {}),
        i.setData({ newOrderDetailInfoVOList: s, newOrderGropList: c });
      for (var d = 0; d < n.orderDetailInfoVOList.length; d++)
        for (
          var h = 0;
          h < n.orderDetailInfoVOList[d].museumOrderUserVOS.length;
          h++
        ) {
          a.makeCode(
            n.orderDetailInfoVOList[d].museumOrderUserVOS[h].electronicTicket,
            d,
            h,
            !1,
          );
          var u = {};
          (u.idx = d), (u.idy = h), o.push(u);
        }
      i.setData({ electronicTickets: o });
    });
  },
  cancelCandidateOrder: function () {
    var e = { orderSn: this.data.content.orderNo };
    wx.showModal({
      title: that.data._t["提示"],
      content: that.data._t["是否确认取消？"],
      confirmText: that.data._t["确定"],
      cancelText: that.data._t["取消"],
      success: function (i) {
        i.confirm &&
          (wx.showLoading({ title: that.data._t["取消"] + "..." }),
          t.cancelCandidateOrder(e).then(function (e) {
            a.showMsg(that.data._t["取消成功"]), wx.hideLoading();
            var t = getCurrentPages(),
              i = t[t.length - 2],
              r = i.data.params;
            i.setData({ refresh: !0 }),
              (r.page = 1),
              i.getOrderList(r),
              wx.navigateBack();
          }));
      },
    });
  },
  expandMore: function () {
    var e = this;
    if ((this.setData({ isShowQr: !this.data.isShowQr }), this.data.isShowQr)) {
      var a = this.data.code_i,
        i = this.data.code_j,
        r = {
          electronicTicket:
            this.data.content.orderDetailInfoVOList[a].museumOrderUserVOS[i]
              .electronicTicket,
        };
      1 == this.data.isShowQrcode &&
        t.getEle(r).then(function (t) {
          e.makeCode(t.data.electronicTicket, a, i, !0);
        });
    }
  },
  getEle: function (e) {
    var a = this,
      i = this.data.code_i,
      r = this.data.code_j,
      n = {
        electronicTicket:
          this.data.content.orderDetailInfoVOList[i].museumOrderUserVOS[r]
            .electronicTicket,
      };
    t.getEle(n).then(function (e) {
      a.makeCode(e.data.electronicTicket, i, r, !0);
    });
  },
  makeCode: function (e, t, a, r) {
    r && wx.showLoading({ title: "" });
    var n = (200 * wx.getSystemInfoSync().windowWidth) / 375,
      o = n,
      s = this,
      c = this.data.content;
    (c.orderDetailInfoVOList[t].museumOrderUserVOS[a].codeUrl = ""),
      new i("myQrcode", {
        text: e,
        width: n,
        height: o,
        colorDark: "#181818",
        colorLight: "white",
        correctLevel: i.CorrectLevel.H,
        callback: function (e) {
          r && wx.hideLoading(),
            (c.orderDetailInfoVOList[t].museumOrderUserVOS[a].codeUrl = e.path),
            s.setData({ content: c }),
            wx.hideLoading();
        },
      });
  },
  copyText: function (e) {
    var t = e.currentTarget.dataset.text;
    wx.setClipboardData({
      data: t,
      success: function (e) {
        wx.hideLoading(), a.showMsg(this.data._t["复制成功"]);
      },
    });
  },
  CallPhone: function () {
    wx.makePhoneCall({ phoneNumber: wx.getStorageSync("telphoneNumber") });
  },
  openTip: function () {
    this.setData({ is_show: !0 });
  },
  Cancel: function (e) {
    this.setData({ is_show: !1 });
  },
  changeQR: function (e) {
    var a = this;
    if (!n) {
      n = !0;
      var i = e.detail.current,
        r = this.data.electronicTickets[i],
        o = e.detail.show,
        s = e.currentTarget.dataset.show;
      if (o || s) {
        (n = !1), this.setData({ code_i: r.idx, code_j: r.idy, currentQR: i });
        var c = {
          electronicTicket:
            this.data.content.orderDetailInfoVOList[r.idx].museumOrderUserVOS[
              r.idy
            ].electronicTicket,
        };
        1 == this.data.isShowQrcode
          ? t.getEle(c).then(function (e) {
              a.makeCode(e.data.electronicTicket, r.idx, r.idy, !0), (n = !1);
            })
          : setTimeout(function () {
              n = !1;
            }, 500);
      } else n = !1;
    }
  },
  changeArrow: function (e) {
    var t = e.currentTarget;
    t.disabled = !0;
    var a = e.currentTarget.dataset.type,
      i = this.data.currentQR;
    "left" == a &&
      i - 1 >= 0 &&
      (this.setData({ currentQR: i - 1 }),
      this.changeQR({ detail: { current: i, show: !1 } })),
      "right" == a &&
        this.data.electronicTickets.length > i + 1 &&
        (this.setData({ currentQR: i + 1 }),
        this.changeQR({ detail: { current: i, show: !1 } })),
      setTimeout(function () {
        t.disabled = !1;
      }, 500);
  },
  toPage: function () {
    wx.navigateTo({
      url:
        "plugin-private://wx393d60d93f70599c/pages/Rule/index?orderType=" +
        this.data.content.orderType +
        "&teamType=" +
        this.data.content.teamType,
    });
  },
  onReady: function () {},
  onShow: function () {},
  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {},
  onReachBottom: function () {},
});
